package com.shqcjd.preinstallglass.ui.activity.remote;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.CardView;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.Button;
import android.widget.ScrollView;

import com.open.androidtvwidget.bridge.EffectNoDrawBridge;
import com.open.androidtvwidget.bridge.OpenEffectBridge;
import com.open.androidtvwidget.view.FrameMainLayout;
import com.open.androidtvwidget.view.MainUpView;
import com.orhanobut.logger.Logger;
import com.shqcjd.preinstallglass.R;
import com.shqcjd.preinstallglass.ui.base.BaseActivity;
import com.shqcjd.preinstallglass.ui.base.BasePresenter;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 专家分类
 */
public class ExpertTypeActivity extends BaseActivity {


    @BindView(R.id.btn_type_1)
    CardView btnType1;
    @BindView(R.id.btn_type_2)
    CardView btnType2;
    @BindView(R.id.btn_type_3)
    CardView btnType3;
    @BindView(R.id.ib_back)
    Button ibBack;
    @BindView(R.id.sv_bg)
    ScrollView svBg;
    private Context mContext;

    @BindView(R.id.mainUpView1)
    MainUpView mMainUpView;
    @BindView(R.id.main_lay)
    FrameMainLayout main_lay11;
    OpenEffectBridge mOpenEffectBridge;
    View mOldFocus;

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_expert_type;
    }

    @Override
    public void initView() {
        mContext = this;

        mMainUpView.setEffectBridge(new EffectNoDrawBridge());
        mOpenEffectBridge = (OpenEffectBridge) mMainUpView.getEffectBridge();
        Drawable testDrawable = null;
        mMainUpView.setUpRectDrawable(testDrawable); // 设置边框图片
        mMainUpView.setUpRectResource(R.drawable.test_rectangle); // 设置边框图片.


        main_lay11.getViewTreeObserver().addOnGlobalFocusChangeListener(new ViewTreeObserver.OnGlobalFocusChangeListener() {
            @Override
            public void onGlobalFocusChanged(final View oldFocus, final View newFocus) {

                if (newFocus != null)
//                    newFocus.bringToFront(); // 防止放大的view被压在下面. (建议使用MainLayout)
                    mMainUpView.setFocusView(newFocus, mOldFocus, 1.0f);
                mOldFocus = newFocus; // 4.3以下需要自己保存.
                // 测试是否让边框绘制在下面，还是上面. (建议不要使用此函数)
//                if (newFocus != null) {
//                    testTopDemo(newFocus, scale);
//                }
            }
        });
    }

    @OnClick({R.id.btn_type_1, R.id.btn_type_2, R.id.btn_type_3, R.id.ib_back})
    public void onViewClicked(View view) {
        Intent intent;
        switch (view.getId()) {
            case R.id.btn_type_1://专家 //专家类型 1专家 2专工 3供应商 0全部
                intent = new Intent(mContext, ExpertListActivity.class);
                intent.putExtra("expertType", 1);
                startActivity(intent);
                break;
            case R.id.btn_type_2://专工
                intent = new Intent(mContext, ExpertListActivity.class);
                intent.putExtra("expertType", 2);
                startActivity(intent);
                break;
            case R.id.btn_type_3://供应商
                intent = new Intent(mContext, ExpertListActivity.class);
                intent.putExtra("expertType", 3);
                startActivity(intent);
                break;
            case R.id.ib_back://返回
                finish();
                break;
        }
    }

    @Override
    protected String getVoiceContent() {
        return "|返回|专家|专工|供应商;";
    }

    @Override
    protected void onVoiceResult(String result) {
        Logger.i("识别结果:"+result);
        switch (result) {
            case "返回":
                finish();
                break;
            case "专家":
                btnType1.performClick();
                break;
            case "专工":
                btnType2.performClick();
                break;
            case "供应商":
                btnType3.performClick();
                break;
        }
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
